package com.basketball.gym.controller;


import com.basketball.gym.pojo.Price;
import com.basketball.gym.pojo.ResponseData;
import com.basketball.gym.pojo.state.ResponseState;
import com.basketball.gym.service.PriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.protocol.RequestDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 赵肖云
 * @since 2021-03-27
 */
@Api(tags = "价格管理")
@RestController
@RequestMapping("/gym/price")
public class PriceController {
    @Autowired
    private PriceService priceService;

    @ApiOperation("修改价格")
    @PreAuthorize("hasAnyRole('admin','superAdmin')")
    @Transactional
    @PutMapping
    public ResponseData<Object> updatePrice(@Validated(Price.update.class) @RequestBody Price price) {
        priceService.updateById(price);
        return new ResponseData<>(ResponseState.SUCCESS.getMessage(), ResponseState.SUCCESS.getValue());
    }

    @ApiOperation("查询价格")
    @GetMapping
    public ResponseData<List<Price>> getPrice(){
        return priceService.getPrice();
    }

}

